Skip to content

[analyzer] Resolve as style module exports#557

Merged
aomarks merged 2 commits intomasterfrom
resolve-class
Jun 28, 2018
Merged

[analyzer] Resolve as style module exports#557
aomarks merged 2 commits intomasterfrom
resolve-class

Conversation

@aomarks
Copy link
Member

@aomarks aomarks commented Jun 28, 2018

Resolves what foo is in export {foo as bar}.

@aomarks aomarks requested a review from rictic June 28, 2018 04:00
@aomarks aomarks changed the title [analyzer] Resolve exports like export {Foo as Baz}. [analyzer] Resolve as style module exports Jun 28, 2018
// Handle cases like `export {Foo as Bar}`.
if (babel.isExportNamedDeclaration(path.node) && !path.node.source) {
for (const specifier of path.node.specifiers) {
if (specifier.exported.name !== specifier.local.name &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this !== check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked it out, the other case is handled separately

Copy link
Member Author

@aomarks aomarks Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the way this works is:

  1. If node is an import from another document, go resolve in that document instead. This logic already has its own handling to make sure that in the foo as bar case, we look for foo in that other document, instead of bar.

  2. Otherwise, look for a feature with the identifier we're resolving in the local scope of node. This is why the export {foo} case already worked without any special handling for that syntax (we know foo and we know the scope). foo as bar didn't work because we didn't do the bar -> foo switch in this local document case.

I took a little stab at unifying the bar -> foo logic between the import and local cases, but it didn't seem to be actually more readable without maybe a larger refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants